/*
 * @Author: 请求热门活动
 * @Date: 2021-03-29 09:58:07
 * @LastEditTime: 2021-04-28 09:40:54
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \active-front\src\api\HotEvent.js
 */
import axios from "../axios/index";

export default {
  // 热门活动
  HotEvents: ({ pageNum = 1, pageSize = 6 } = {}) =>
    axios.get(`act/initIndex/${pageNum}/${pageSize}`).then(function(response) {
      return response.data;
    }),
  //获取活动详情
  activeDetail: aid =>
    axios.get(`act/activeDetail/${aid}`).then(function(response) {
      console.log(response);
      return response.data;
    }),
  //活动报名
  activeEnroll: ({ uid }) =>
    axios.get(`act/activeEnroll/${uid}`).then(function(response) {
      console.log("活动报名", response);
      return response.data;
    }),
  //查询负责人详情
  workerInfo: id =>
    axios.post(`workerInfo/${id}`).then(function(response) {
      console.log("负责人详情", response);
      return response.data;
    }),
  //用户参加/报名的活动详情
  userActiveList: ({ pageNum = 1, pageSize = 6 } = {}) =>
    axios
      .get(`act/userActiveList/${pageNum}/${pageSize}`)
      .then(function(response) {
        return response.data.data;
      }),
  //上传头像
  uploadIcon: formData =>
    axios
      .post(`file/uploadIcon`, formData, {
        headers: { "Content-Type": "multipart/form-data" }
      })
      .then(function(response) {
        console.log("上传文件", response);
        return response.data;
      }),
  //新增活动
  releaseActive: formData =>
    axios
      .post(`admin/releaseActive`, formData, {
        headers: { "Content-Type": "multipart/form-data" }
      })
      .then(function(response) {
        console.log("新增活动", response);
        return response.data;
      }),
  // 查看活动
  enrollUsers: ({ aid = 1, pageNum = 1, pageSize = 10 } = {}) =>
    axios
      .get(`admin/enrollUsers/${aid}/${pageNum}/${pageSize}`)
      .then(function(response) {
        // console.log(response.data)
        return response.data;
      }),
  // 管理员确认活动的报名
  checkconfirm: ({ uid = 0, aid = 0 } = {}) =>
    axios.get(`admin/confirmEnroll/${uid}/${aid}`).then(function(response) {
      console.log(response);
      return response.data;
    }),
  // 管理员搜索用户
  searchEnrollUser: ({
    pageNum = 1,
    pageSize = 6,
    info = "",
    aid = 1,
    confirm = -1
  }) =>
    axios
      .post("admin/searchEnrollUser", {
        pageNum,
        pageSize,
        info,
        aid,
        confirm
      })
      .then(function(response) {
        console.log(response);
        return response.data;
      }),
  // 活动报名搜索
  searchActives: ({ pageNum = 1, pageSize = 6, info = "" }) =>
    axios
      .post("act/searchActives", {
        pageSize,
        pageNum,
        info
      })
      .then(function(response) {
        console.log(response);
        return response.data;
      }),
  //通过TagId查询列表数据

  searchList: ({ pageNum = 1, pageSize = 6, tagId }) =>
    axios
      .get(`act/tagActives/${tagId}/${pageNum}/${pageSize}`)
      .then(function(response) {
        console.log(response);
        return response.data.data;
      }),

  // 导出excel已报名的文件
  downloadExcel: ({ aid = 1, name = "" }) =>
    axios
      .post(
        "file/downloadExcel",
        { aid, name },
        {
          responseType: "blob" //防止导出文件破损或乱码
        }
      )
      .then(function(res) {
        const link = document.createElement("a");
        let blob = new Blob([res.data], { type: "application/vnd.ms-excel" });
        link.style.display = "none";
        link.href = URL.createObjectURL(blob);
        link.setAttribute("download", name + "报名表" + ".xls");
        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link);
        return res;
      })
      .catch(error => {
        this.$Notice.error({
          title: "错误",
          desc: "网络连接错误"
        });
        console.log(error);
      }),
  deleteaction: ({ aid = 1 }) =>
    axios.get(`admin/closeEnroll/${aid}`).then(function(response) {
      console.log(response);
      return response.data;
    }),
  // 批量确认
  confirmAllation: ({ aid = 1, uids = [] }) =>
    axios
      .post("admin/confirmEnrollList", { aid, uids })
      .then(function(response) {
        console.log(response);
        return response.data;
      }),
  // 管理员的查询接口
  updateActiveInfo: ({ form }) =>
    axios.post("admin/updateActiveInfo", form).then(function(response) {
      console.log(response);
      return response.data;
    }),
  //获取用户所有信息
  newsDetail: () =>
    axios.post("act/newsDetail").then(function(res) {
      return res.data.data;
    }),
  // --->信息详情跳转到查看活动界面
  getUserActivesByAid: id =>
    axios.get("act/getUserActivesByAid/" + id).then(function(res) {
      console.log("r信息详情跳转到查看活动界面es", res);
      return [res.data.data];
    }),
  //修改活动信息中的管理员删除文件列表中的某个文件
  deletefilePath: ({ id = 1, filePath = "" }) =>
    axios
      .post("admin/deleteActiveFile", { id, filePath })
      .then(function(response) {
        console.log(response);
        return response.data;
      }),
  // 管理员上传文件
  updateActiveFile: formData =>
    axios
      .post("admin/updateActiveFile", formData)
      .then(function(response) {
        console.log(response);
        return response.data;
      })
      .catch(function(err) {
        return "错误";
      })
};
